package com.it.text;

import com.it.domain.Student;

import java.util.ArrayList;
import java.util.Scanner;

public class ArrayList02 {
    public static void main(String[] args) {


        ArrayList<Student> list = new ArrayList<>();

        for (int i = 0; i < 3; i++) {
            System.out.println("请输入第" + (i+1) + "位:");
            getData(list);
        }

        for (int i = 0; i < list.size(); i++) {
            Student stu = list.get(i);
            System.out.println(stu.getName() + "------" + stu.getAge());
        }

    }

    private static void getData(ArrayList<Student> list) {
        Scanner sc = new Scanner(System.in);
        String name;
        int age;
        System.out.println("请输入学生的姓名：");
        name = sc.next();
        System.out.println("请输入学生的年龄：");
        age = sc.nextInt();

        Student stu = new Student(name,age);
        list.add(stu);
    }


}
